package com.example.apidbtest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;
import java.util.stream.IntStream;

@RestController
@SpringBootApplication
public class ApiDbTestApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApiDbTestApplication.class, args);
    }

    private static final String[] SCHOOL_NAMES = {
            "北京大学", "清华大学", "复旦大学", "上海交通大学", "浙江大学",
            "南京大学", "武汉大学", "中山大学", "西安交通大学", "哈尔滨工业大学"
    };

    private static final int[] STATUSES = {0, 1, 2};

    @PostMapping("/api/vocational_school")
    R test(@RequestBody Req req) {
        Random random = new Random();

        List<zzxx> dataList = IntStream.range(0, 10) // 生成10条数据
                .mapToObj(i -> new zzxx(
                        String.format("%03d", i + 1), // 三位数格式的学校代码
                        SCHOOL_NAMES[random.nextInt(SCHOOL_NAMES.length)], // 随机学校名+附属中学
                        STATUSES[random.nextInt(STATUSES.length)] // 随机状态
                ))
                .toList();
        return new R(List.of(dataList));
    }

}
